<?php

namespace App\Http\Controllers\Web;

use App\Repositories\HistoryRepository;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class HistoryController extends Controller
{
    //
    private $historyRepository;

    public function __construct(HistoryRepository $historyRepository)
    {
        $this->historyRepository = $historyRepository;
    }

    public function index(Request $request) {
        $search_name = $request->get('name');
        $search_phone = $request->get('phone');
        $condition = [];
        if($search_name){
            $condition = [
                'name' => ['like', '%'.$search_name.'%'],
            ];
        }
        if($search_phone){
            $condition = [
                'phone' => ['like', '%'.$search_phone.'%'],
            ];
        }

        $list = $this->historyRepository->paginateWithCondition(10,[], $condition);

        $search = [
            'name' => $search_name,
            'phone' => $search_phone
        ];
        return view('history/index',compact('list', 'search'));
    }
}
